package org.example.gui.model;

import org.example.entity.Budget;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.text.DecimalFormat;
import java.util.List;

public class BudgetTableModel implements TableModel {
    private final String[] columnNames = {"月份", "预算", "当月消费"};
    private final String[] monthName = {
            "1月", "2月", "3月", "4月", "5月", "6月",
            "7月", "8月", "9月", "10月", "11月", "12月", "年度总预算"};
    public List<Budget> budgetList;

    @Override
    public int getRowCount() {
        return budgetList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return String.class;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (0 == columnIndex)
            return monthName[rowIndex];
        if (1 == columnIndex)
            return budgetList.get(rowIndex).getValue();
        if (2 == columnIndex) {
            DecimalFormat df = new DecimalFormat("0.00");
            return df.format(budgetList.get(rowIndex).getRecordTotalSpend());
        }

        return null;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {

    }
}
